package com.abel.bigwater.data

import com.abel.bigwater.msg.RtuMsg
import com.abel.bigwater.msg.RtuMsgType
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import java.util.*

@RunWith(SpringRunner::class)
@SpringBootTest
class MsgHelperTest {

    @Autowired
    var msgHelper: MsgHelper? = null

    @Test
    fun sendRawPacket() {
        msgHelper!!.sendRawPacket(RtuMsg().apply {
            station = "1"
            msgType = RtuMsgType.DATA_BIN.name
            rawBinary = byteArrayOf(1, 2, 3, 4, 5, 6)
            rawHex = BcdString.hexString(rawBinary!!)
            recvTime = Date()
        })
    }

    @Test
    fun sendHandleTopic() {
        msgHelper!!.sendHandleTopic(RtuMsg().apply {
            station = "2"
            msgType = RtuMsgType.STATUS.name
            text = "hello, handle!"
        })
    }
}